/*
 邀请面试对话框与查看企业联系方式
 @绑定查看联系方式
 * @userName:    用户名
 * @url:        ajax回调地址
 * @interviewUrl 邀请面试状态返回地址
 * @crsf:       crsf令牌
 * @resumeId:   简历ID
 * @callBack    响应返回的状态
 * 示例
 @绑定面试邀请框
 $(".button2").click(function(){
 $.interview({userName:"",url:"",interviewUrl:"", crsf:"",resumeId: "",callBack:function(status){
 //alert(status);//0发布成功，1您今天已邀请过了，或未选择面试工作2企业未发布工作岗位
 }});
 });
 */
$(function () {
    $.extend({
        //企业发送面试邀请
        interview: function (settings) {
            var setvar = {
                className: "interview_button",
                crsf: "",
                url: "",
                interviewUrl: "",
                postJobUrl: "",
                resumeId: "",
                jobId: 0,
                userName: "",
                callBack: function () {}
            };
            $.extend(setvar, settings);

            $.post(setvar.url, {
                '_token': setvar.crsf,
                'resumeId': setvar.resumeId
            }, function (data) {
                switch (data.status) {
                    case 2:
                        //提示充值
                        resumeBuy = layer.confirm('亲，您的会员已到期或简历数已用尽。', {
                                btn: ['重新购买套餐', '稍候再买'] //按钮
                            },
                            function () {//success
                                //跳转到vip套餐页面
                                window.open("/company/my_order", "_blank");
                                layer.close(resumeBuy);
                            },
                            function () {//false
                                layer.close(resumeBuy);
                            }
                        );
                        break;
                    case 3:
                        var toInterView = layer.open({
                            type: 1,
                            title: "邀请<b>[" + setvar.userName + '</i>]</b>参加面试',
                            skin: 'layer-interview',
                            area: ['420px', '350px'],//['420px', '350px']
                            resize: false,
                            move: false,
                            btn: false,
                            content: "<div id='interviewDiv'></div>",
                            success: function () {
                            }
                        });
                        inviteTitle = data.inviteTitle;
                        html = '';
                        html += "<div class='noJobDiv'>";
                        html += "<div class='haveNoJob'>";
                        html += "<p class='first-tip'>您还没有发布的职位</p>";
                        html += "<p class='second-tip'>发布职位，320万人才给您投递简历</p>";
                        html += "<a href=" + setvar.postJobUrl + " class='button' target='_blank'>立即发布职位</a>";
                        html += "</div>";
                        html += "</div>";
                        $("#interviewDiv").html(html);
                        setvar.callBack(data.status);
                        break;
                    case 1:
                        var toInterView = layer.open({
                            type: 1,
                            title: "邀请<b>[" + setvar.userName + '</i>]</b>参加面试',
                            skin: 'layer-interview',
                            area: ['420px', '330px'],//['420px', '350px']
                            resize: false,
                            move: false,
                            btn: false,
                            content: "<div id='interviewDiv'></div>",
                            success: function () {
                            }
                        });
                        inviteTitle = data.inviteTitle;
                        html = '';
                        //option
                        html += "<div class='interviewbox'>";
                        html += "<form action='#' method='post' name='interviewForm' id='interviewForm' >";//company/interviewnote
                        html += "<div class='jobtitle'><i>面试职位：</i>";
                        html += "<input type='hidden' name='_token' value='" + setvar.crsf + "'>";
                        html += "<input type='hidden' name='resumeId' value='" + setvar.resumeId + "'>";
                        html += "<select name='jobId' id='jobId'>";
                        html += "<option value=''>请选择岗位</option>";
                        $.each(inviteTitle, function (key, value) {
                            if (setvar.jobId == value.value) {
                                html += "<option value='" + value.value + "' selected>" + value.text + "</option>";
                            } else {
                                html += "<option value='" + value.value + "'>" + value.text + "</option>";
                            }

                        });
                        html += '</select>';
                        html += "</div>";

                        html += "<div class='interviewtime'>";
                        html += "<span><i>面试时间：</i><input class='datainp wicon timeput' id='inpstart' name='inpstart' type='text' placeholder='邀请面试时间' value='" + data.interViewTime + "' readonly></span>";
                        html += "</div>";

                        html += "<div class='jobnote'>";
                        html += "<span><i>相关备注：</i><textarea name='jobnote'></textarea></span>";
                        html += "</div>";
                        //备注
                        html += "<div class='interviewbutton'>";
                        html += "<em>*将以短信或邮件通知对方</em><input type='submit' value='发送邀请' id='checkInterView'>";
                        html += "</div>";
                        html += "</form>";
                        html += "</div>";
                        $("#interviewDiv").html(html);
                        var start = {
                            format: 'YYYY-MM-DD hh:mm:ss',
                            minDate: $.nowDate(0), //设定最小日期为当前日期
                            festival: false,
                            skinCell: "jedateblue",
                            //isinitVal:true,
                            maxDate: '2099-06-16 23:59:59', //最大日期
                            fixed: false
                        };
                        $("#inpstart").jeDate(start);
                        //面试邀请表单提交
                        $("#checkInterView").click(function () {
                            var queryString = $("#interviewForm").formSerialize();
                            $.ajax({
                                url: setvar.interviewUrl,
                                dataType: "json",
                                data: queryString,
                                type: "POST",
                                time: 0,
                                success: function (data) {
                                    //console.log(data);
                                    if (data.status == '0') {
                                        layer.msg(data.msg, {icon: 6});
                                        setvar.callBack(data.status);
                                        layer.close(toInterView);
                                        return true;
                                    } else {
                                        layer.msg(data.msg, {icon: 5});
                                        setvar.callBack(data.status);
                                        layer.close(toInterView);
                                        return false;
                                    }
                                },
                                error: function (data) {
                                    var msgErr = '';
                                    var errors = $.parseJSON(data.responseText);
                                    $.each(errors, function (index, value) {
                                        msgErr += value + ";<br>";
                                    });
                                    layer.msg(msgErr, {icon: 5});
                                    layer.close(toInterView);
                                },
                                complete: function () {
                                }
                            });
                            return false;
                        });
                        break;
                }
            });
        },
        //企业查看联系方式
        getContact: function (settings) {
            var setvar = {
                className: "getcontact",
                resumeId: "",//简历id
                userName: "",//简历人名称
                url: "",//url('/personcontact')
                crsf: "",
                callBack: function () {}
            };
            $.extend(setvar, settings);

            $.post(setvar.url, {
                '_token': setvar.crsf,
                'resumeId': setvar.resumeId
            }, function (data) {
                var html = '';
                switch (data.status) {
                    case 0:
                        //提示充值
                        resumeBuy = layer.confirm('亲，您的会员已到期或简历数已用尽。', {
                                btn: ['重新购买套餐', '稍候再买'] //按钮
                            },
                            function () {//success
                                //跳转到vip套餐页面
                                window.open("/company/my_order", "_blank");
                                layer.close(resumeBuy);
                            },

                            function () {//false
                                layer.close(resumeBuy);
                            }
                        );
                        break;
                    case 1:
                        html += "<li><span>联系电话</span>" + data.mobile + "</li>";
                        html += "<li><span>邮箱地址</span>" + data.email + "</li>";
                        html += "<li><span>QQ号码<i></i></span>" + data.qq + "</li>";
                        $('.baseInfo .detail2 .seeContact').remove();
                        $('.baseInfo .detail2').eq(1).html(html);

                        break;
                    case 2:
                        resumeBuy = layer.confirm('亲，您的会员已到期或简历数已用尽。', {
                                btn: ['重新购买套餐', '稍候再买'] //按钮
                            },
                            function () {//success
                                //跳转到vip套餐页面
                                window.open("/company/my_order", "_blank");
                                layer.close(resumeBuy);

                            },
                            function () {//false
                                layer.close(resumeBuy);
                            });
                        break;
                }
                setvar.callBack(data.status);
                $("#closeGetContact").click(function () {
                    layer.close(lookcontact);
                });
            });
        }
    });
});
